/*     */ package com.zimbra.cs.service.account;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import com.zimbra.cs.zimlet.ZimletPresence;
/*     */ import com.zimbra.cs.zimlet.ZimletPresence.Presence;
/*     */ import com.zimbra.cs.zimlet.ZimletUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ModifyZimletPrefs
/*     */   extends AccountDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  39 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  40 */     Account account = getRequestedAccount(zsc);
/*     */     
/*  42 */     if (!canModifyOptions(zsc, account)) {
/*  43 */       throw ServiceException.PERM_DENIED("can not modify options");
/*     */     }
/*  45 */     Map<String, Object> attrs = new HashMap();
/*     */     
/*  47 */     ZimletPresence availZimlets = ZimletUtil.getAvailableZimlets(account);
/*     */     
/*  49 */     String addEnabled = "+zimbraPrefZimlets";
/*  50 */     String delEnabled = "-zimbraPrefZimlets";
/*  51 */     String addDisabled = "+zimbraPrefDisabledZimlets";
/*  52 */     String delDisabled = "-zimbraPrefDisabledZimlets";
/*     */     
/*  54 */     for (Element eZimlet : request.listElements("zimlet")) {
/*  55 */       String zimletName = eZimlet.getAttribute("name");
/*  56 */       String presense = eZimlet.getAttribute("presence");
/*  57 */       ZimletPresence.Presence userPrefPresence = ZimletPresence.Presence.fromString(presense);
/*     */       
/*     */ 
/*  60 */       if (userPrefPresence == ZimletPresence.Presence.mandatory) {
/*  61 */         throw ServiceException.INVALID_REQUEST("invalid zimlet presence: " + presense, null);
/*     */       }
/*  63 */       ZimletPresence.Presence defaultPresence = availZimlets.getPresence(zimletName);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  73 */       if ((defaultPresence == null) || (defaultPresence == ZimletPresence.Presence.mandatory) || (defaultPresence == userPrefPresence))
/*     */       {
/*     */ 
/*  76 */         StringUtil.addToMultiMap(attrs, delEnabled, zimletName);
/*  77 */         StringUtil.addToMultiMap(attrs, delDisabled, zimletName);
/*     */ 
/*     */ 
/*     */ 
/*     */       }
/*  82 */       else if (userPrefPresence == ZimletPresence.Presence.enabled)
/*     */       {
/*  84 */         StringUtil.addToMultiMap(attrs, addEnabled, zimletName);
/*  85 */         StringUtil.addToMultiMap(attrs, delDisabled, zimletName);
/*     */       }
/*     */       else {
/*  88 */         StringUtil.addToMultiMap(attrs, delEnabled, zimletName);
/*  89 */         StringUtil.addToMultiMap(attrs, addDisabled, zimletName);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*  94 */     Provisioning prov = Provisioning.getInstance();
/*  95 */     prov.modifyAttrs(account, attrs);
/*     */     
/*  97 */     Element response = zsc.createElement(AccountConstants.MODIFY_ZIMLET_PREFS_RESPONSE);
/*  98 */     doResponse(prov, response, account);
/*  99 */     return response;
/*     */   }
/*     */   
/*     */   private void doResponse(Provisioning prov, Element response, Account acct) throws ServiceException {
/* 103 */     ZimletPresence userZimlets = ZimletUtil.getUserZimlets(acct);
/* 104 */     for (String zimletName : userZimlets.getZimletNames()) {
/* 105 */       Zimlet zimlet = prov.getZimlet(zimletName);
/* 106 */       if ((zimlet != null) && (zimlet.isEnabled()) && (!zimlet.isExtension())) {
/* 107 */         Element eZimlet = response.addElement("zimlet");
/* 108 */         eZimlet.addAttribute("name", zimletName);
/* 109 */         eZimlet.addAttribute("presence", userZimlets.getPresence(zimletName).toString());
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/ModifyZimletPrefs.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */